package 五月打卡;

/*
 * @author  YxinMiracle
 * @date  2022-05-06 9:17
 * @Gitee: https://gitee.com/yxinmiracle
 */

import java.util.ArrayList;
import java.util.List;

public class RecentCounter {

    int count;
    List<Integer> timeList;
    int left = 0;

    public RecentCounter() {
        this.count = 0;
        this.timeList = new ArrayList<>();
    }

    public int ping(int t) {
        this.timeList.add(t);
        int leftTarget = t-3000;
        return findIndex(this.timeList.size(), leftTarget);
    }

    public int findIndex(int size, int leftTarget) {
        int right = size;
        while (this.left < right) {
            int min = (this.left + right) >> 1;
            if (this.timeList.get(min)>=leftTarget){
                right = min;
            }else {
                this.left = min+1;
            }
        }
        System.out.println("right:"+right);
        System.out.println("t:"+leftTarget);
        return size - right + 1;
    }


}
